package com.zky.gulimall.order.web;

import com.zky.gulimall.order.entity.OrderEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.UUID;

/**
 * @Description 页面测试controller
 * @Author 张开源
 * @Date 2022/12/8 23:59
 * @Version 1.0
 **/
@Controller
@Slf4j
public class WebPageController {
    @Resource
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/test/createOrder")
    @ResponseBody
    public String testCreateOrder() {
        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setCreateTime(new Date());
        orderEntity.setOrderSn(UUID.randomUUID().toString());
        orderEntity.setId(1L);
        orderEntity.setMemberId(88L);
        orderEntity.setStatus(0);
        orderEntity.setModifyTime(new Date());
        orderEntity.setReceiverDetailAddress("浙江省杭州市余杭区");
        orderEntity.setPayAmount(new BigDecimal(100));
        rabbitTemplate.convertAndSend("order-event-exchange", "order.create.order", orderEntity);
        log.warn("订单延迟消息发送完毕,orderEntity:{}", orderEntity);
        return "ok";
    }


    @GetMapping("/{page}.html")
    public String listPage(@PathVariable("page") String page) {
        log.warn("listPage  page:" + page);
        return page;
    }
}
